﻿/*
 * Created by SharpDevelop.
 * User: BadaninMV
 * Date: 22.01.2015
 * Time: 14:08
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Linq;
namespace Region.Utils
{
  /// <summary>
  /// Description of Comparer.
  /// </summary>
  public class IEnumerableComparer : IEqualityComparer<IEnumerable<Object>>
  {
  
      public bool Equals(IEnumerable<Object> b1, IEnumerable<Object> b2)
      {
        if (b1.Count()!=b2.Count()) return false;
        IEnumerator<Object> ib1 = b1.GetEnumerator();
        IEnumerator<Object> ib2 = b2.GetEnumerator();
        while(ib1.MoveNext() && ib2.MoveNext())
        {
          if (!ib1.Current.Equals(ib2.Current)) return false;
        }
        return true;
      }
  
  
      public int GetHashCode(IEnumerable<Object> bx)
      {
        int hCode = 0;
        foreach(Object o in bx)
          hCode = hCode ^ o.GetHashCode();            
        return hCode.GetHashCode();
      }
  
  }    
}
